package com.kimstore.gui.main;

import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class CredentialsJOptionPane {

    private JFrame frame;
    private JPanel panel;
    private JTextField usernameField;
    private JPasswordField passwordField;

    public CredentialsJOptionPane(JFrame parent) {
        panel = new JPanel();
        this.frame = parent;

        //Set JPanel layout using GridLayout
        panel.setLayout(new GridLayout(4, 1));

        //Create a label with text (Username)
        JLabel username = new JLabel("Username");

        //Create a label with text (Password)
        JLabel password = new JLabel("Password");

        //Create text field that will use to enter username
        usernameField = new JTextField(12);

        //Create password field that will be use to enter password
        passwordField = new JPasswordField(12);

        //Add label with text (username) into created panel
        panel.add(username);

        //Add text field into created panel
        panel.add(usernameField);

        //Add label with text (password) into created panel
        panel.add(password);

        //Add password field into created panel
        panel.add(passwordField);
    }

    public int showDialog() {
        return JOptionPane.showConfirmDialog(frame, panel, "Enter administrator username and password to continue.", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    }

    public JTextField getUsernameField() {
        return usernameField;
    }

    public void setUsernameField(JTextField usernameField) {
        this.usernameField = usernameField;
    }

    public JPasswordField getPasswordField() {
        return passwordField;
    }

    public void setPasswordField(JPasswordField passwordField) {
        this.passwordField = passwordField;
    }
}
